package chaoyue.study.nio;

import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * 通道间的数据传输
 */
public class FileChannelCopy {
    public static void main(String[] args) throws Exception {
        // 创建两个fileChannel
        RandomAccessFile aFile = new RandomAccessFile("/Users/chaoyue/Downloads/demo1.txt", "rw");
        FileChannel fromChannel = aFile.getChannel();
        RandomAccessFile bFile = new RandomAccessFile("/Users/chaoyue/Downloads/demo2.txt", "rw");
        FileChannel toChannel = bFile.getChannel();

        toChannel.transferFrom(fromChannel, 0, fromChannel.size());


        bFile.close();
        aFile.close();
        System.out.println("over ");
    }
}
